package be.novelfaces.component.numpaddecsep;

import java.io.IOException;

import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.context.FacesContext;

import org.richfaces.cdk.annotations.JsfRenderer;

import be.novelfaces.component.AbstractRenderer;
import be.novelfaces.component.encoder.Encoder;
import be.novelfaces.component.util.element.PanelWriter;

@ResourceDependencies({
		@ResourceDependency(library = "novelfaces", name = "js/jquery-nf.min.js"),
		@ResourceDependency(library = "novelfaces", name = "js/jquery.numpadDecSeparator-1.1.2-min.js"),
		@ResourceDependency(library = "novelfaces", name = "js/novelfaces.js") })
@JsfRenderer(family = "be.novelfaces.component", //
type = "be.novelfaces.component.NumpadDecimalSeparatorRenderer")
public class NumpadDecimalSeparatorRenderer extends
		AbstractRenderer<NumpadDecimalSeparator> {

	private Encoder jsEncoder = new NumpadDecimalSeparatorJSEncoder();

	@Override
	protected void decodeComponent(FacesContext facesContext,
			NumpadDecimalSeparator component) {
	}

	@Override
	protected void encodeBeginComponent(FacesContext facesContext,
			NumpadDecimalSeparator component) throws IOException {
		PanelWriter.create().startElement(component)
				.getAttributesWriterBuilder(component).withId()
				.writeAttributes();
	}

	@Override
	protected void encodeEndComponent(FacesContext facesContext,
			NumpadDecimalSeparator component) throws IOException {
		jsEncoder.encode(facesContext, component);
		PanelWriter.create().endElement();
	}

	@Override
	protected Class<NumpadDecimalSeparator> getComponentClass() {
		return NumpadDecimalSeparator.class;
	}

}
